
var userId = searchToObj(location.search).userId;
function searchToObj(str) {
  var newStr = str.substr(1);
  var strArr = newStr.split('&'); 
  var obj = {};
  for (var i = 0; i < strArr.length; i++) {
    var o = strArr[i].split('=');
    obj[o[0]] = o[1];
  }
  return obj;
}
initaddcent2()
function initaddcent2() {
    $.ajax({
        url: '/student/details',
        method: 'POST',
        data: {
            userId
        }
      })
        .done(function (res) {   
            addcent2(res.data)
        })
        .fail(function (err) {
          console.log('请求失败：', err);
        });
}

function addcent2(user) {
  $('#ly_val1').val(user.name);
  $('#ly_val2').val(user.class);
  $('#ly_val3').val(user.gender);
  $('#ly_val4').val(user.parentname);
  $('#ly_val5').val(user.parentphone);
  $('#ly_val6').val(user.years);
  $('#ly_val7').val(user.phone);
  $('#ly_val8').val(user.Email);
  $('#ly_val9').val(user.address);
  $('#ly_val10').val(user.Dates);
  $('#ly_val11').val(user.hobby);
  $('#ly_val12').val(user.introduce);
  $('#ly_val13').val(user.Awards);
}



$('.p1').on('click',function() {
  let nowname = $('#ly_val1').val();
  let nowclass = $('#ly_val2').val();
  let nowgender = $('#ly_val3').val();
  let nowparentname = $('#ly_val4').val();
  let nowparentphone = $('#ly_val5').val();
  let nowyears = $('#ly_val6').val();
  let nowphone = $('#ly_val7').val();
  let nowEmail = $('#ly_val8').val();
  let nowaddress = $('#ly_val9').val();
  let nowDates = $('#ly_val10').val();
  let nowhobby = $('#ly_val11').val();
  let nowintroduce = $('#ly_val12').val();
  let nowAwards = $('#ly_val13').val();
  $.ajax({
    url: '/student/revamp',
    method: 'POST',
    data: {
        userId,
        nowname,
        nowclass,
        nowgender,
        nowphone,
        nowEmail,
        nowDates
    }
  })
    .done(function (res) { 
      // parent.layer.msg('修改成功', {icon: 1},{time: 2000,});
    })
    .fail(function (err) {
      console.log('请求失败：', err);
    });
  $.ajax({
    url: '/student/revamp1',
    method: 'POST',
    data: {
      nowyears, 
      nowintroduce,
      nowaddress,
      nowhobby,
      nowAwards,
      nowparentname,
      nowparentphone,
      userId
    }
  })
    .done(function (res) { 
      parent.layer.msg('修改成功', {icon: 1},{time: 2000,});
    })
    .fail(function (err) {
      console.log('请求失败：', err);
    });
  $('#ly_val1').val('');
  $('#ly_val2').val('');
  $('#ly_val3').val('');
  $('#ly_val4').val('');
  $('#ly_val5').val('');
  $('#ly_val6').val('');
  $('#ly_val7').val('');
  $('#ly_val8').val('');
  $('#ly_val9').val('');
  $('#ly_val10').val('');
  $('#ly_val11').val('');
  $('#ly_val12').val('');
  $('#ly_val13').val('');
})
